package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.ERP.MaterialDataErp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IMaterialDataErpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * erp物料主数据Controller
 *
 * @author ruoyi
 * @date 2023-04-07
 */
@Api(tags = "物料主数据(erp同步)api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/erpMaterial" )
public class MaterialDataErpController extends BaseController {

    private final IMaterialDataErpService iMaterialDataErpService;

    /**
     * 查询erp物料主数据列表
     */
    @ApiOperation(value = "查询erp物料主数据列表",response = MaterialDataErp.class)
    @GetMapping("/list")
    public TableDataInfo list(MaterialDataErp materialDataErp)
    {
        startPage();
        List<MaterialDataErp> list = iMaterialDataErpService.selectList(materialDataErp);
        return getDataTable(list);
    }

    /**
     * 查询erp物料主数据所有
     */
    @ApiOperation(value = "查询erp物料主数据所有",response = MaterialDataErp.class)
    @GetMapping("/getListAll")
    public AjaxResult getListAll(MaterialDataErp materialDataErp)
    {
        List<MaterialDataErp> list = iMaterialDataErpService.selectList(materialDataErp);
        return AjaxResult.success(list);
    }

    /**
     * 导出erp物料主数据列表
     */
    @Log(title = "erp物料主数据" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MaterialDataErp materialDataErp) {
        LambdaQueryWrapper<MaterialDataErp> lqw = new LambdaQueryWrapper<MaterialDataErp>(materialDataErp);
        List<MaterialDataErp> list = iMaterialDataErpService.list(lqw);
        ExcelUtil<MaterialDataErp> util = new ExcelUtil<MaterialDataErp>(MaterialDataErp. class);
        return util.exportExcel(list, "erpMaterial" );
    }

    /**
     * 获取erp物料主数据详细信息
     */
    @ApiOperation(value = "获取erp物料主数据详细信息")
    @GetMapping(value = "/{dataId}" )
    public AjaxResult getInfo(@PathVariable("dataId" ) Long dataId) {
        return AjaxResult.success(iMaterialDataErpService.getById(dataId));
    }

    /**
     * 新增erp物料主数据
     */
    @ApiOperation(value = "新增erp物料主数据")
    @Log(title = "erp物料主数据" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialDataErp materialDataErp) {
        return toAjax(iMaterialDataErpService.save(materialDataErp) ? 1 : 0);
    }

    /**
     * 修改erp物料主数据
     */
    @ApiOperation(value = "修改erp物料主数据")
    @Log(title = "erp物料主数据" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialDataErp materialDataErp) {
        return toAjax(iMaterialDataErpService.updateById(materialDataErp) ? 1 : 0);
    }

    /**
     * 删除erp物料主数据
     */
    @ApiOperation(value = "删除erp物料主数据")
    @Log(title = "erp物料主数据" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}" )
    public AjaxResult remove(@PathVariable Long[] dataIds) {
        return toAjax(iMaterialDataErpService.removeByIds(Arrays.asList(dataIds)) ? 1 : 0);
    }
}
